import type { BrandRecord } from '@/DatabaseType/Brand';
import type { PaginationConfig } from '@/types';
import { ServiceProxy } from '@/constant';
import type { RequestResult } from '@/utils/request';
import { request } from '@umijs/max';

// 获取角色列表
export async function getBrandList(
  params: Partial<Pick<BrandRecord, 'id' | 'name'>> & PaginationConfig,
): Promise<
  RequestResult<{
    total: number;
    list: BrandRecord[];
  }>
> {
  return request(`${ServiceProxy.DefaultPrefix}/brand`, {
    method: 'GET',
    params,
  });
}

// 删除
export async function deleteBrand(id: number): Promise<RequestResult<void>> {
  return request(`${ServiceProxy.DefaultPrefix}/brand/${id}`, {
    method: 'DELETE',
  });
}

// 更新
export async function updateBrand(
  id: number,
  data: Pick<BrandRecord, 'marketPrice' | 'coverUrl' | 'name'>,
): Promise<RequestResult<void>> {
  return request(`${ServiceProxy.DefaultPrefix}/brand/${id}`, {
    method: 'PUT',
    data,
  });
}

// 创建
export async function addBrand(
  data: Pick<BrandRecord, 'marketPrice' | 'coverUrl' | 'name'>,
): Promise<RequestResult<void>> {
  return request(`${ServiceProxy.DefaultPrefix}/brand`, {
    method: 'POST',
    data,
  });
}
